package com.silong.swing.myWindows;

import javax.swing.*;
import java.awt.*;

/**
 * Created by 龙哥 on 2022-01-17 15:25
 * Silong Software.
 * 自定义网格布局管理器
 */

public class MyFrameGridLayout extends JFrame {

    JButton button1;
    JButton button2;
    JButton button3;
    JButton button4;
    JButton button5;

    public MyFrameGridLayout(){
        init();
    }

    private void init(){

        button1 = new JButton("按钮一");
        button2 = new JButton("按钮二");
        button3 = new JButton("按钮三");
        button4 = new JButton("按钮四");
        button5 = new JButton("按钮五");

        Container window = this.getContentPane();
        this.setSize(800, 600);
        this.setLocationRelativeTo(null); //距中
        this.setTitle("GridLayout边框布局窗体");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //退出窗口关闭程序

        //设置窗体的网络布局管理器，rows行数，cols列数，水平边距，垂直边距
        window.setLayout(new GridLayout(3, 2, 10, 10));

        //排列规则，所有网格大小相同，所有添加到窗体上的组件都会被显示出来
        //行数不变列数变
        //组件按照从左上到右下的顺序排列
        window.add(button1);
        window.add(button2);
        window.add(button3);
        window.add(button4);
        window.add(button5);

    }

}
